<?php

use Webman\GatewayWorker\Gateway;
use Webman\GatewayWorker\BusinessWorker;
use Webman\GatewayWorker\Register;

return [
    'gateway'  => getenv('WEBSOCKET_RUN_GATEWAY') === 'true' ? [
        'handler'     => Gateway::class,
        'listen'      => 'websocket://0.0.0.0:' . getenv('WEBSOCKET_GATEWAY_PORT'),
        'count'       => cpu_count(),
        'reloadable'  => false,
        'constructor' => [
            'config' => [
                'lanIp'           => getenv('WEBSOCKET_GATEWAY_LAN_IP'),
                'startPort'       => getenv('WEBSOCKET_GATEWAY_START_PORT'),
                'pingInterval'    => getenv('WEBSOCKET_GATEWAY_PING_INTERVAL'),
                'pingData'        => getenv('WEBSOCKET_GATEWAY_PING_DATA'),
                'registerAddress' => getenv('WEBSOCKET_REGISTER_IP') . ':' . getenv('WEBSOCKET_REGISTER_PORT'),
                'onConnect'       => function () {
                },
            ]
        ]
    ] : null,
    'worker'   => getenv('WEBSOCKET_RUN_WORKER') === 'true' ? [
        'handler'     => BusinessWorker::class,
        'count'       => cpu_count() * 2,
        'constructor' => [
            'config' => [
                'eventHandler'    => plugin\webman\gateway\Events::class,
                'name'            => getenv('APP_NAME') . 'WebsocketBusinessWorker',
                'registerAddress' => getenv('WEBSOCKET_REGISTER_IP') . ':' . getenv('WEBSOCKET_REGISTER_PORT'),
            ]
        ]
    ] : null,
    'register' => getenv('WEBSOCKET_RUN_REGISTER') === 'true' ? [
        'handler'     => Register::class,
        'listen'      => 'text://0.0.0.0:' . getenv('WEBSOCKET_REGISTER_PORT'),
        'count'       => 1, // Must be 1
        'constructor' => []
    ] : null,
];
